import { ApiProperty } from "@nestjs/swagger";
import { Comments } from "@prisma/client";
import { Transform } from "class-transformer";
import { IsInt, IsNotEmpty, IsOptional, IsString, Min } from "class-validator";

import { DbCommonField } from "@/core/types/db-common-field.type";

export class CreateCommentDto implements CustomOmit<Comments, DbCommonField | "id" | "userId" | "status"> {
    @Transform(({ value }) => Number(value))
    @IsInt()
    @Min(0)
    @ApiProperty({ description: "评论所属ID", example: 0, required: true })
    targetId: number;

    @IsOptional()
    @Transform(({ value }) => Number(value))
    @IsInt()
    @Min(0)
    @ApiProperty({ description: "父评论ID", example: 0, required: true })
    parentId: number;

    @Transform(({ value }) => value.trim())
    @IsString()
    @IsNotEmpty()
    @ApiProperty({ description: "评论内容", example: "笑死我了", required: true })
    content: string;
}
